package cn.hunan.dzzk.action;

import cn.hunan.dzzk.dao.TUserDAO;
import cn.hunan.dzzk.dao.TUserDAOImpl;
import cn.hunan.dzzk.entity.TUser;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
	
private String userName;
	
	private String userPass;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPass() {
		return userPass;
	}

	public void setUserPass(String userPass) {
		this.userPass = userPass;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String execute() throws Exception {
		TUserDAO uDAO = new TUserDAOImpl();
		TUser t = new TUser();
		t.setUserName(userName);
		t.setUserPass(userPass);
		boolean flag = uDAO.ValidateUser(t);
		if (flag) {
			
			ActionContext.getContext().getSession().put("user", getUserName());
			return Action.SUCCESS;
		} else {

			return Action.LOGIN;
		}
	}

	@Override
	public void validate() {
		
	}
	
	
	

}
